<link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
<link rel="stylesheet" href="../../../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<link rel="stylesheet" href="../../../css/layuimini.css?v=2.0.1" media="all">
<link rel="stylesheet" href="../../../css/themes/default.css" media="all">
<link rel="stylesheet" href="../../../css/public.css" media="all">
<style>
	.layui-form-select dl{
		max-height: 200px;
	}
</style>
<div class="layuimini-main">
	<div class="layui-form layuimini-form">
		<div class="layui-form-item">
			<label class="layui-form-label">环境</label>
			<div class="layui-input-block">
				<select name="envId" id="envId"></select>
			</div>
		</div>
		<input type="hidden" name="appId" id="appId2"/>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="confirmBtn">确认构建</button>
			</div>
		</div>
	</div>
</div>
<script src="../../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../../js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script src="../../../js/common.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
			appId = localStorage.getItem('appId_' + parent.layui.$("#userName").val());
		
		$("#appId2").val(appId);
		
		initEnv(form, $, appId);
		
        form.on('submit(confirmBtn)', function(data) {
			doBuild($, appId, $("#envId").val(), parent.branchName, closeCurrent);
            return false;
        });
    });
	
	function closeCurrent(){
		parent.layer.close(parent.layer.getFrameIndex(window.name));
	}
	
	function initEnv(form, $, appId) {
		$.ajax({
			url: '/app/env/search',
			type: 'POST',
			dataType: "json",
			contentType: 'application/json;charset=UTF-8',
			data: JSON.stringify({'appId': appId, 'pageSize': 1000, 'pageNum': 1}),
			success: function(res){
				data = res.data
				var firstEnv = 0;
				var opt = '<option value="">请选择或输入</option>';
				for(var k in data){
					if(k == 0){
						firstEnv = data[k].id;
					}
					opt = opt.concat("<option value='"+ data[k].id +"'>"+ data[k].envName +"</option>");
				}
				if(opt != ''){
					$("#envId").html(opt);
					form.render('select');
				}
			},
			error: function(data){
				layer.msg(data.message, {icon: 5, shift: 6});
			}
		});
	}
</script>